package demo.vo.common;

import java.util.List;

/**
 * 分页信息
 *
 * @author hanjy
 */
public class Page<T> {

    /**
     * 当前页
     */
    private int pageNum;
    /**
     * 每页的数量
     */
    private int pageSize;
    /**
     * 总记录数
     */
    private long total;
    /**
     * 结果集
     */
    private List<T> data;

    /**
     * @param pageNum  第几页
     * @param pageSize 每页多少条
     * @param total    总数
     * @param list     列表
     */
    public Page(int pageNum, int pageSize, long total, List<T> list) {
        super();
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.data = list;
    }

    /**
     * 分页查询的起始行
     *
     * @return
     */
    public static int offset(int pageNum, int pageSize) {
        return (pageNum - 1) * pageSize;
    }

    /**
     * 分页查询的起始行
     *
     * @return
     */
    public int offset() {
        return (pageNum - 1) * pageSize;
    }


    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalNumber() {
        return total;
    }

    public void setTotalNumber(long totalNumber) {
        this.total = totalNumber;
    }

    public long getTotalPage() {
        return (total + pageSize - 1) / pageSize;
    }


    public List<T> getContent() {
        return data;
    }

    public void setContent(List<T> content) {
        this.data = content;
    }

}
